// CityMap.cpp : implementation file
//

#include "stdafx.h"
#include "Antony.h"
#include "CityMap.h"


// CCityMap

IMPLEMENT_DYNAMIC(CCityMap, CStatic)

CCityMap::CCityMap()
{
    m_map = NULL;
    m_agents = NULL;
}

CCityMap::~CCityMap()
{
}


BEGIN_MESSAGE_MAP(CCityMap, CStatic)
	ON_WM_PAINT()
END_MESSAGE_MAP()

// CCityMap message handlers

void CCityMap::SetNodeMap(CNodeMap* map)
{
    m_map = map;
}

void CCityMap::SetAgentVec(CAgentPtrVec* agents)
{
    m_agents = agents;
}

void CCityMap::OnPaint()
{
	// Get device context 
    CPaintDC dc(this);
	CDC* mdc = new CDC();
	mdc->CreateCompatibleDC(&dc);

	// Get bitmap rect	
    CRect rect;
    GetClientRect(&rect);

	// Draw BMP of NYC
	CBitmap bmp;
	bmp.LoadBitmap(IDB_NYC);
	mdc->SelectObject(&bmp);
	dc.BitBlt(0, 0, rect.Width(), rect.Height(), mdc, 0, 0, SRCCOPY);

    // Draw node map
    if (m_map)
        m_map->Paint(rect, dc);

    // Draw agents
    if (m_agents && m_agents->size() > 0)
    {
        for (CAgentPtrVecIter it = m_agents->begin(); it != m_agents->end(); ++it)
        {
            CAgent* agent = *it;
            if (agent->GetType() == ETYPE_CAR && m_drawCars 
                || agent->GetType() == ETYPE_TAXI && m_drawTaxis)
                (*it)->Paint(dc);            
        }
    }

    delete mdc;
}
